﻿var request = require( 'request' );
var readline = require( 'readline' );

var rl = readline.createInterface( {
    input: process.stdin,
    output: process.stdout
});

rl.question( "Input the url of the server (default localhost): ", function ( url ) {
    if ( !url || url == "" )
        url = "http://localhost:1337";
    url += "/api";

    rl.question("Email? ", function ( email ) {
        console.log(email);
        request.post( { url: url, json: { cmd: "login", email: email } }, function ( err, res, body ) {
            console.log(err);
            console.log(body);

            rl.question("Code? ", function ( code ) {
                console.log(code);
                request.post( { url: url, json: { cmd: "validate", email: email, code: code } }, function ( err, res, body ) {
                    console.log(err);
                    console.log(body);

                    rl.close();
                });
            });
        });
    });
});


